package finanz.kontrolle;

import classes.Parametros;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class TrocaUrlActivity extends Activity implements OnClickListener{
	
	private Parametros par = Parametros.getInstance();
	
	public void onCreate( Bundle bundle ) {
		super.onCreate( bundle );
		setContentView( R.layout.trocaurl );
		
		Button btnTrocar = ( Button ) findViewById( R.id.btnTrocar );
		btnTrocar.setOnClickListener( this );
		
		Button btnCancelar = ( Button ) findViewById( R.id.btnCancelarTroca );
		btnCancelar.setOnClickListener( this );
	}

	public void onClick( View arg0 ) {
		switch ( arg0.getId()  ) {
			case R.id.btnTrocar:
				
				EditText txtUrl = ( EditText ) findViewById( R.id.txtUrl );
				
				int mensagem = R.string.msgUrlTrocada;
				
				if ( txtUrl.getText().length() <= 0 ) {
					mensagem = R.string.msgPreenchaUrl;
				} else {
					par.setUrl( txtUrl.getText().toString() );
				}
					
				Toast t = Toast.makeText( this, mensagem, Toast.LENGTH_SHORT );
				t.setGravity(Gravity.CENTER, 0, 0 );
				t.show();
				
				break;
			case R.id.btnCancelarTroca:
				break;
		}
		
		Intent i =new Intent( TrocaUrlActivity.this, FinanzKontrolleDroidActivity.class );
		startActivity( i );
		finish();
	}
}